﻿/// Write a program that finds the most frequent number in an array. 
/// Example:  {4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3}  4 (5 times)


using System;

class zad_9
{
    static void Main()
    {
        int[] arr = { 4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 }; //{ 2, 2, 2, 1, 1, 2, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1, 5 };

        // Dictionary is much better but anyway it's wort a try :) !?!
        int[][] jaggetArrey = new int[arr.Length][];

        // init jagget arrey
        for (int i = 0; i < arr.Length; i++)
        {
            int[] tempArr = {arr[i], 0};
            jaggetArrey[i] = tempArr; 
        }

        int maxRepeat = 0;
        int numberRepeat = jaggetArrey[0][1];

        for (int i = 0; i < arr.Length; i++)
        {
            for (int j = 0; j <= i; j++)
            {
                if (jaggetArrey[j][0] == arr[i])
                {
                    jaggetArrey[j][1]++;

                    if (jaggetArrey[j][1] > maxRepeat)
                    {
                        maxRepeat = jaggetArrey[j][1];
                        numberRepeat = jaggetArrey[j][0];
                    }
                }
            }

            
        }

        //for (int i = 0; i < jaggetArrey.GetLength(0); i++)
        //{

        //    for (int j = 0; j < 2; j++)
        //    {
        //        Console.Write(jaggetArrey[i][j] + " ");
        //    }

        //    Console.WriteLine();
        //}

       
        Console.WriteLine(" {0}  ({1} times)", numberRepeat, maxRepeat);
    }
}
